<?php

class m110920_012203_employee_tag extends CDbMigration {
	public function safeUp() {
		$this
			->createTable('erp_employee_tag',
				array(
					'id' => 'pk',
					'key' => 'string',
					'name' => 'string',
					'description' => 'string',
				));
		$this->createIndex("employee_tag_key", 'erp_employee_tag', 'key');
		
		$this
			->createTable('erp_employee_tag_employee',
				array(
					'id' => 'pk',
					'tagId' => 'int',
					'employeeId' => 'int',
				));
		$this->createIndex("employee_tag_tag_id", 'erp_employee_tag_employee', 'tagId');
		$this
			->addForeignKey('fk_employee_tag_tag_id', 'erp_employee_tag_employee', 'tagId',
				'erp_employee_tag', 'id', 'CASCADE', 'CASCADE');
		$this->createIndex("employee_tag_employee_id", 'erp_employee_tag_employee', 'employeeId');
		$this
			->addForeignKey('fk_employee_tag_employee_id', 'erp_employee_tag_employee',
				'employeeId', 'erp_employee', 'id', 'CASCADE', 'CASCADE');

	}

	public function safeDown() {
		$this->dropTable('erp_employee_tag_employee');
		$this->dropTable('erp_employee_tag');
	}
}
